<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
    <meta charset="utf-8">
    <title>Directions service</title>
    <script  src="__PUBLIC__static/js/jquery.js"></script>
    <link rel="stylesheet" type="text/css" href="__PUBLIC__static/css/login.css">
    <link href="__PUBLIC__/layui/css/layui.css" rel="stylesheet">
    <script type="text/javascript" src="__PUBLIC__/layui/layui.all.js"></script>

</head>
<body>

<div class="login">
    <div class="input-box">
        <div class="title">TMS System</div>
        <div class="input-item">
            <input type="text" name="username" id="username" value="" placeholder="username" required>
        </div>
        <div class="input-item">
            <input type="password" name="password" id="password" value="" placeholder="password" required>
        </div>
        <div class="input-item">
            <a href="javascript:;" id="login">登陆</a>
        </div>
    </div>
</div>
<script>

    function g(id){
        return document.getElementById(id).value;
    }
    $('#login').click(function () {
        let username = g('username');
        let password = g('password');
        if(username==''){
            layer.msg('用户名不为空');
            return false;
        }
        if(password==''){
            layer.msg('密码不能为空');
            return false;
        }
        $.ajax({
            type: "POST",
            dataType: "json",
            url: "{{:url('/login')}}" ,
            data: {username:username,password:password},
            success: function (result) {
                if (result.code == 200) {
                    window.location.href="{{:url('/')}}"
                }else{
                    layer.msg('用户名或者密码错误');
                }
            },
            error : function() {
                layer.msg('异常');
            }
        });
    })



</script>
</body>
</html>
